package com.lm.security.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author lm_jcf
 * @date 2018/4/26 16:54
 *
 * 可以拿到调用的传进来参数值. 但是不能拿到原始http请求和响应，真正处理请求的方法，
 */
@Aspect
@Component
public class TimeAspect {

    @Around("execution(* com.lm.security.controller.UserController.*(..))")
    public Object handleControllerMethod(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {

        System.out.println("time aspect start");
        Object[] os = proceedingJoinPoint.getArgs();
        for (Object o : os) {
            System.out.println("arg" +o);
        }


        long start = new Date().getTime();

        Object object = proceedingJoinPoint.proceed();
        System.out.println("time interceptor 耗时:" + (new Date().getTime() - start));
        System.out.println("time aspect end");

        return object;
    }

}
